// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './vuex'

import $ from 'jquery'
import semantic from 'semantic'
import '../node_modules/semantic-ui-css/semantic.min.css'
import './assets/css/me.css'

import axios from 'axios'
import VueAxios from 'vue-axios'
//滚动
import "./assets/js/jquery.scrollTo.min.js"
//动态加载图片
import "./assets/js/jquery.scrollLoading-min.js"
//加载的动画样式
import "./assets/css/animate.css"
//格式化时间
import Moment from 'moment'


//访问的
axios.defaults.baseURL = "http://localhost:8080"
    // 将token添加到axios请求头部
axios.interceptors.request.use(
    config => {
        if (localStorage.getItem('token')) {
            config.headers.token = localStorage.getItem('token')
        }
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

//配置路由拦截器
router.beforeEach((to, from, next) => {
    if (to.matched.length == 0)
        return next('/404')
    var i = to.path.search("admin")
        //路径不包含/admin
    if (i == -1) {
        return next()
    }
    const token = window.localStorage.getItem('token')
    if (!token) {
        return next('/login')
    }
    next()
})
Vue.use(VueAxios, axios)

// 定义全局时间戳过滤器
Vue.filter('formatDate', function(value, type) {
    return Moment(value).format(type)
})

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    components: { App },
    template: '<App/>'
})